// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/order/api/WorkOrderApi'

import AddClass from '@api/order/model/InsertWorkOrderReq'
import BaseClass from '@api/order/model/WorkOrderDto'
import FileClass from '@api/order/model/WorkOrderFileDto'

const CLIENT = CORE.grpcCLIENT(Client)

const FILE = [FileClass, 'workOrderFileDto']
// const FILE = [FileClass, 'workOrderFileDto', 1]
// const BASE = [BaseClass, NAME, '', (dto, obj) => CORE.grpcDTO(dto, obj, FILE)]

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '工单新增') {
    const imageList = one.image.map((fileUrl) => ({ fileUrl, fileName: fileUrl.split('/').pop(), fileType: 1 }))
    const BASE = [BaseClass, 'workOrderDto', '', (dto, obj) => {
      CORE.grpcDTO(dto, obj, [...FILE, imageList])
    }]
    const DTO = CORE.grpcDTO(AddClass, one, BASE)
    const resp = await CORE.grpc(TIP, CLIENT, 'insertWorkOrder', DTO)
    return [CORE.grpcOK(TIP), resp.workOrderDto || {}]
  },
}
